from Portfolio.Portfolio import Portfolio
from Common.EventHandle import EventHandle

class Backtesting:

	def __init__(self, portfolio, event_list):
	
		self.portfolio = portfolio
		self.event_list = event_list
	
	def run(self):
	
		running_times = set()
		
		for event in self.event_list:
			running_times |= set(event.trigger_times())
			
		running_times = list(running_times)
		running_times.sort()
		
		for t in running_times:
		
			for event in self.event_list:
			
				if event.is_triggered(t):
					
					activity_list = event.create_activities(t, self.portfolio)
					
					if activity_list:
						for activity in activity_list:
							self.portfolio.add_activity(activity)
						
					
					
			
	